import axios from "axios";

// eslint-disable-next-line
export default {
  get: ({ curPage, eachPage }) =>
    axios.get("/api/shoppingCart", {
      params: {
        curPage, eachPage
      }
    })
      .then(({ data }) => data),

  // 删除商品
  delComm: (_id) =>
    axios({
      method: "delete",
      url: "/api/shoppingCart/delComm",
      data: {
        _id
      }
    })
      .then(data => data),

  // 新增商品
  addComm: ({ user_id, seckill_id, count }) =>
    axios({
      method: "post",
      url: "/api/shoppingCart/addComm",
      data: {
        user_id,
        seckill_id,
        count
      }
    })
      .then(({ data }) => data),

  // 修改商品数量
  changeCount: ({ count, _id }) =>
    axios({
      method: "patch",
      url: "/api/shoppingCart/changeCount",
      data: {
        count,
        _id
      }
    })
      .then(({ data }) => data),

  // 通过用户id查找对应购物车商品
  findCart: (user_id) =>
    axios.get("/api/shoppingCart/findCart", {
      params: {
        user_id
      }
    })
      .then(({ data }) => data),

  // 通过商品id找到整条数据
  findComm: (commodity_id) =>
    axios.get("/api/shoppingCart/findComm", {
      params: {
        commodity_id
      }
    })
      .then(({ data }) => data),

  // 获取购物车下拉框初始数据
  getAddCartData: ({ user_id, seckill_id }) =>
    axios.get("/api/shoppingCart/getAddCartData", {
      params: {
        user_id,
        seckill_id
      }
    })
      .then(({ data }) => data),
}